import { tab, address, recentlyBrowse, city } from 'js/cache'
import * as types from './mutations-type'

export const setTab = function ({ commit }, tabs) {
  commit(types.CATEGORY, tab.setTab(tabs))
}

export const setAddress = function ({ commit }, list) {
  commit(types.addressInfo, address.setAddress(list))
}

export const clearAddress = function ({ commit }) {
  commit(types.addressInfo, address.clearAddress())
}

// 最近浏览, 加入缓存
export const setBrowse = function ({commit, state}, data) {
  commit(types.BROWSE, recentlyBrowse.setBrowse(data))
}

// 清除一条，最近浏览
export const deleteOne = function ({commit}, id) {
  commit(types.BROWSE, recentlyBrowse.deleteOne(id))
}

// 选择地址
export const selectCity = function ({commit}, targetCity) {
  commit(types.CITY, city.setCity(targetCity))
}

export const setSearchGoods = function ({commit}, goods) {
  commit(types.SEARCH_GOODS, goods)
}
